package com.timber.util;

import java.util.*;
import javax.swing.JOptionPane;

import com.timber.util.Util;

import java.awt.*;

public class SLMessage
{

  public static int YES = JOptionPane.YES_OPTION;
  public static int NO = JOptionPane.NO_OPTION;
  public static int CANCEL = JOptionPane.CANCEL_OPTION;

  /**
   *	display Error dialog
   *
   *	@param parent
   *	@param msg
   */
  public static void Error( Component parent, String msg )
  {
    Toolkit.getDefaultToolkit().beep();

    Util.error( msg );

    JOptionPane.showMessageDialog(parent, msg, "Error", JOptionPane.ERROR_MESSAGE);

  }

  /**
   *	display Error dialog. write message and exception to log file
   *
   *	@param parent
   *	@param ex
   *	@param src
   *	@param msg
   */
  public static void Error( Component parent, Exception ex, String src, String msg )
  {
    Toolkit.getDefaultToolkit().beep();

    Util.error( src, msg, ex );

    msg = ( msg == null ? ex.getMessage() : msg );
    JOptionPane.showMessageDialog(parent, msg, "Error", JOptionPane.ERROR_MESSAGE);
  }

  /**
   *	display Error dialog
   *
   *	@param parent
   *	@param ex
   */
  public static void Error( Component parent, Exception ex )
  {
    Error( parent, ex, null, null );
  }

  /**
   *	display Error dialog
   *
   *	@param parent
   *	@param ex
   *	@param msg
   */
  public static void Error( Component parent, Exception ex, String msg )
  {
    Error( parent, ex, null, msg );
  }

  /**
   *	display Error dialog
   *
   *	@param msg
   */
  public static void Error(  String msg )
  {
    Error( null, msg );
  }

  /**
   *	display Info dialog
   *	@param parent
   *	@param msg
   */
  public static void Info( Component parent, Object msg )
  {
    JOptionPane.showMessageDialog(parent, msg, "Information", JOptionPane.INFORMATION_MESSAGE);

  }

  public static void Info( Component parent, String src, Object msg )
  {
    JOptionPane.showMessageDialog(parent, msg, "Information", JOptionPane.INFORMATION_MESSAGE);
  }

  /**
   *	display Info dialog
   *	@param msg
   */
  public static void Info( Object msg )
  {
    Info( null, msg );
  }


  /**
   *	display confirm dialog Yes / No / Cancel
   */
  public static int Confirm( Component parent, Object msg )
  {
    return JOptionPane.showConfirmDialog( parent, msg,
					   "Confirm", JOptionPane.YES_NO_CANCEL_OPTION);
  }

  /**
   *	display confirm dialog Yes / No
   */
  public static int ConfirmYN( Object msg )
  {
    return ConfirmYN( null, msg, "Confirm" );
  }

  /**
   *	display confirm dialog Yes / No
   */
  public static int ConfirmYN( Component parent, Object msg )
  {
    return ConfirmYN( parent, msg, "Confirm" );
  }

  /**
   *	display confirm dialog Yes / No
   */
  public static int ConfirmYN( Component parent, Object msg, String title )
  {
    return JOptionPane.showConfirmDialog( parent, msg, title, JOptionPane.YES_NO_OPTION );
  }
}
